import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
import yaml
import cv2
from modules.xfeat import XFeat
from evaluation.dual_softmax_matcher import DualSoftMaxMatcher
from evaluation.superpoint.mega_pose_est_mnn import MegaDepthPoseMNNBenchmark
from evaluation.superpoint.superpoint import SuperPoint


def get_best_device(verbose = False):
    device = torch.device('cpu')
    if torch.cuda.is_available():
        device = torch.device('cuda')
    elif torch.backends.mps.is_available():
        device = torch.device('mps')
    else:
        device = torch.device('cpu')
    if verbose: print (f"Fastest device found is: {device}")
    return device


if __name__ == "__main__":
    config = {
            'nms_radius': 5,
            'keypoint_threshold': 0.005,
            'max_keypoints': 4096}
    weight_path = "/home/liyuke/PycharmProjects/SuperGluePretrainedNetwork-master/models/weights/superpoint_v1.pth"
    # model = XFeat(weights=weight_path)
    model = SuperPoint(config).cuda()
    matcher = DualSoftMaxMatcher()


    mega_1500 = MegaDepthPoseMNNBenchmark()
    mega_1500.benchmark(descriptor_model = model,matcher_model = matcher)